const parseJs = require('./cyhook');

let openPro = {
    summary: "",
    * beforeSendResponse(requestDetail, responseDetail) {
        // if (requestDetail.url.indexOf('.js') != -1){
        if (true){
            const responseLo = responseDetail.response;
            try{
                var text = parseJs(responseLo.body.toString());
            }catch (e) {
                var text = responseLo.body.toString();
            }
            if (responseLo.header['Content-Type'] != undefined && responseLo.header['Content-Type'].indexOf('html') != -1) {
                responseLo.body = "<script>if(window.cbb_yhh==undefined){window.cbb_eval=eval;eval=function(x){if(x.length<13000){cbb_eval(x);};window.cbb_vvnn=WebSocket;var ws=new window.cbb_vvnn('ws://127.0.0.1:418');ws.onopen=function(){ws.send(x)};ws.onmessage =function(evt){console.log(evt.data);cbb_eval(evt.data);};};window.cbb_yhh=1}</script>" + text;
            }else {
                // responseLo.body = 'if(window.cbb_yhh==undefined){window.cbb_eval=eval;eval=function(x){if(x.length<13000){cbb_eval(x);};window.cbb_vvnn=WebSocket;var ws=new window.cbb_vvnn(\'ws://127.0.0.1:418\');ws.onopen=function(){ws.send(x)};ws.onmessage =function(evt){console.log(evt.data);cbb_eval(evt.data);};};window.cbb_yhh=1}'+ text
                responseLo.body = text;
            }
            return {response: responseLo};
        };
    },
};
module.exports = openPro;